package com.ruoyi.life.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.life.domain.FeStandard;
import com.ruoyi.life.service.IFeStandardService;
import com.ruoyi.omp.api.domain.NyCheckMeter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 水电收费标准Controller
 *
 * @author cjie
 * @date 2021-11-06
 */
@Api(tags = " 水电收费标准")
@RestController
@RequestMapping("/feStandard")
public class FeStandardController extends BaseController {
    @Autowired
    private IFeStandardService feStandardService;

    /**
     * 查询总表当月分摊
     */
    @ApiOperation(value="查询总表当月分摊", notes="查询总表当月分摊")
    @GetMapping("/listTotalCheckMater")
    public AjaxResult listTotalCheckMater(NyCheckMeter nyCheckMeter) {
        return AjaxResult.success(feStandardService.listTotalCheckMater(nyCheckMeter));
    }

    /**
     * 查询水电收费标准列表
     */
    @ApiOperation(value="查询水电收费标准列表", notes="查询水电收费标准列表")
    @PreAuthorize(hasPermi = "life:feStandard:list")
    @GetMapping("/list")
    public TableDataInfo list(FeStandard feStandard) {
        startPage();
        List<FeStandard> list = feStandardService.selectFeStandardList(feStandard);
        return getDataTable(list);
    }

    /**
     * 导出水电收费标准列表
     */
    @ApiOperation(value="导出水电收费标准列表", notes="导出水电收费标准列表")
    @PreAuthorize(hasPermi = "life:feStandard:export")
    @Log(title = "水电收费标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeStandard feStandard) throws IOException {
        List<FeStandard> list = feStandardService.selectFeStandardList(feStandard);
        ExcelUtil<FeStandard> util = new ExcelUtil<FeStandard>(FeStandard.class);
        util.exportExcel(response, list, "水电收费标准数据");
    }
    /**
     * 获取水电收费标准详细信息
     */
    @ApiOperation(value="获取水电收费标准详细信息", notes="获取水电收费标准详细信息")
    @PreAuthorize(hasPermi = "life:feStandard:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(feStandardService.selectFeStandardById(id));
    }

    /**
     * 新增水电收费标准
     */
    @ApiOperation(value="新增水电收费标准", notes="新增水电收费标准")
    @PreAuthorize(hasPermi = "life:feStandard:add")
    @Log(title = "水电收费标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeStandard feStandard) {
        return feStandardService.insertFeStandard(feStandard);
    }

    /**
     * 修改水电收费标准
     */
    @ApiOperation(value="修改水电收费标准", notes="修改水电收费标准")
    @PreAuthorize(hasPermi = "life:feStandard:edit")
    @Log(title = "水电收费标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeStandard feStandard) {
        return toAjax(feStandardService.updateFeStandard(feStandard));
    }

    /**
     * 删除水电收费标准
     */
    @ApiOperation(value="删除水电收费标准", notes="删除水电收费标准")
    @ApiImplicitParam(name = "ids", value = "水电收费标准ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "life:feStandard:remove")
    @Log(title = "水电收费标准", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(feStandardService.deleteFeStandardByIds(ids));
    }

    /**
     * 创建水电费账单
     */
    @ApiOperation(value="创建水电费账单", notes="创建水电费账单")
    @PreAuthorize(hasPermi = "life:feStandard:add")
    @Log(title = "创建水电费账单", businessType = BusinessType.INSERT)
    @PostMapping("/createFeeBill")
    public AjaxResult createFeeBill(String id) {
        return feStandardService.createFeeBill(id);
    }
}
